

package cuttings;

import java.net.*;
import java.util.* ;
import java.lang.Object.*;

public class MyGame
{
    int gameID;
    String hostName;
    Vector<String> Participants = new Vector<String>();
    Vector<String> Attackers = new Vector<String>();
    Vector<String> Defenders = new Vector<String>();

    MyGame(String userName)
    {
        hostName = userName;
        gameID = userName.hashCode();
    }

    public void addParticipant(String userName)
    {
        Participants.add(userName);
    }


    public void addAttacker(String userName, int sendToPeers) throws Exception
    {
        //check if user is defender previously
        checkIfDefender(userName);

        if(!Attackers.contains(userName))
           Attackers.add(userName);

        updateADLists();

        if(sendToPeers==1)
        {
            //for(int i=0;i<Participants.size();i++)
            //SendSocketsList.sendToPeer(Participants.get(i),"#:addAttacker:"+hostName+":"+userName+":0:");
        }

    }

    public void addDefender(String userName, int sendToPeers) throws Exception
    {
        checkIfAttacker(userName);

        if(!Defenders.contains(userName))
           Defenders.add(userName);

        updateADLists();

        if(sendToPeers==1)
        {
            //SendSocketsList.sendToAll("#:addDefender:" + userName);
        }
    }

    public void checkIfDefender(String userName)
    {
        Defenders.remove(userName);
    }

    public void checkIfAttacker(String userName)
    {
        Attackers.remove(userName);
    }

    public void updateADLists()
    {
        String[] sta = new String[Attackers.size()];
        //Menu.updateAttackers(Attackers.toArray(sta));
        //Menu.updateAttackers(Attackers);

        String[] std = new String[Defenders.size()];
        Menu.updateDefenders(Defenders.toArray(std));
    }

}
